package com.fms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fms.mapper.ProductMapper;
import com.fms.entity.Product;
import com.fms.service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    private final ProductMapper productMapper;
    //暂时没用
    @Override
    public List<Product> getProductList() {
        LambdaQueryWrapper<Product> queryWrapper = new LambdaQueryWrapper<>();
        return productMapper.selectList(queryWrapper);
    }

    @Override
    public String addProduct(Product product) {
        if(product.getId()==null) {
            productMapper.insert(product);
            return "新建成功!";
        }else {
            productMapper.updateById(product);
            return "修改成功!";
        }
    }

    @Override
    public String deleteProduct(String id) {
        productMapper.deleteById(id);
        return "商品删除成功!";
    }

    @Override
    public String deleteProducts(Product[] products) {
        for (Product product : products) {
            productMapper.deleteById(product.getId());
        }
        return "商品删除成功!";
    }
}
